/*
 * RS_Handler.java
 *
 * Created on March 29, 2007, 7:43 PM
 *
 */

package edu.byu.isys413.group1E;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/** The purpose of this class is to perform tasks related to the RevenueSource table
 *but not attainable through the abstract RevenueSourceDAO.
 *
 * @author Travis Kulbeth
 */
public class RS_Handler {
    
    /** Contains an instance of RS_Handler*/
    private static RS_Handler instance = null;
    
    /** Creates a new instance of RS_Handler */
    public RS_Handler() {}
    
    /**Retrieves an instance of the BackupHandler object
     *@return instance of BackupHandler
     */
    public static synchronized RS_Handler getInstance() {
        if (instance == null) {
            instance = new RS_Handler();
        }
        return instance;
    }

    
    /** Retrieves the type of revenue source according to the 
     *RevenueSourceID.
     *@param revSrcID contains the revenue source id for the object.
     *@return the type of Revenue source that will be used to find the
     *appropriate DAO.
     */
    public synchronized String getRSType(String id){
            String type = "";
            try {
            // a SELECT the type of revenue source FROM table WHERE id=guid
            Connection conn = ConnectionPool.getInstance().get();
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery("SELECT TypeRS FROM Revenue_Source WHERE RevenueSourceID = '" + id + "'");
            conn.commit();

            //retrieve the type and send it back
            if (rs.next()) {
                type = rs.getString("TypeRS");
            }
        } catch (ConnectionPoolException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        return type;
    }
}
